/*************
author:: libo
license:: MIT
*****************/
#include<Mesh/libcell_iterator.h>
#include<iterator/cstruct_iterator.h>
#define iterator_v lib_cell_iterator_vertices
#define iterator_f lib_cell_iterator_faces
#define iterator_c lib_cell_iterator_cells
#define iterator_edge lib_cell_iterator_edge

#define quote lib_cell_quote

iterator_edge operator++(iterator_edge&ie)
{
    if(ie.f==NULL||ie.v==NULL)
    {
        ie.f=NULL;ie.v=NULL;
        return ie;
    }
    template_v* v=NULL;template_f* f=NULL;
    for(int i=0;i<ie.f->vertices_size;i++)
    {
        if(ie.f->vertices[i]!=ie.v)
        {
            v=ie.f->vertices[i];
            break;
        }
    }
    ie.v=v;
    if(v==NULL)
    {
        ie.f=NULL;
        return ie;
    }
    for(Node* nit=v->faces;nit!=NULL;nit=(Node*)(nit->Next))
    {
        if(nit->value!=ie.f)
        {
            f=(template_f*)(nit->value);
            break;
        }
    }
    ie.f=f;

    if(ie.f==ie.mark)
    {
        ie.v=NULL;
        ie.f==NULL;
    }
    return ie;
}
iterator_edge operator++(iterator_edge&ie,int)
{
    iterator_edge ie1=ie;
    if(ie.f==NULL||ie.v==NULL)
    {
        ie.f=NULL;ie.v=NULL;
        return ie1;
    }
    template_v* v=NULL;template_f* f=NULL;
    for(int i=0;i<ie.f->vertices_size;i++)
    {
        if(ie.f->vertices[i]!=ie.v)
        {
            v=ie.f->vertices[i];
            break;
        }
    }
    ie.v=v;
    if(v==NULL)
    {
        ie.f=NULL;
        return ie1;
    }
    for(Node* nit=v->faces;nit!=NULL;nit=(Node*)(nit->Next))
    {
        if(nit->value!=ie.f)
        {
            f=(template_f*)(nit->value);
            break;
        }
    }
    ie.f=f;
    if(ie.f==ie.mark)
    {
        ie.f=NULL;
        ie.v=NULL;
    }


    return ie1;

}
